package com.happyclub.lbjdao;

import com.happyclub.pojo.TbActivity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;

public interface SendActivity extends JpaRepository<TbActivity,String> {

    /**
     * @Author 高欢
     * @Description  对活动进行更新
     * @Date 11:42 2019/4/4
     **/
    @Modifying
    @Query(value = "update TB_ACTIVITY u set u.ACTIVITY_DETAIL = :activityDetail,u.ACTIVITY_END_TIME = :activityEndTime,u.ACTIVITY_BEGIN_TIME = :activityBeginTime,u.ACTIVITY_MAX_PEOPLE = :activityMaxPeople,u.UPDATE_TIME = SYSDATE,u.ACTIVITY_EXPIRED_TIME = :activityExpiredTime ,u.ACTIVITY_BEGIN_LOCATION = :activityBeginLocation, u.ACTIVITY_COVER = :activityCover,u.ACTIVITY_TITLE = :activityTitle where u.ID = :id",nativeQuery = true)
    int updateActivity(@Param("activityDetail") String activityDetail, @Param("activityEndTime") Date activityEndTime, @Param("activityBeginTime") Date activityBeginTime, @Param("activityMaxPeople") int activityMaxPeople, @Param("activityExpiredTime") Date activityExpiredTime, @Param("activityBeginLocation") String activityBeginLocation,@Param("activityCover") String activityCover , @Param("activityTitle") String activityTitle,@Param("id") String id);

    /**
     * @Author 高欢
     * @Description  通过传入的活动主键ID来增加相应的浏览次数
     * @Date 9:25 2019/4/5
     **/
    @Modifying
    @Query(value = "update TB_ACTIVITY u set u.ACTIVITY_VIEW_COUNT = u.ACTIVITY_VIEW_COUNT + 1 , u.UPDATE_TIME = SYSDATE where u.ID = :id",nativeQuery = true)
    int updateActivityViewNum(@Param("id") String id);

    /**
     * @Author 高欢
     * @Description  根据活动主键修改活动是否通过审核
     * @Date 10:57 2019/4/6
     **/
    @Modifying
    @Query(value = "update TB_ACTIVITY u set u.OK = :ok , u.UPDATE_TIME = SYSDATE where u.ID = :id",nativeQuery = true)
    int updateAvtivityOk(@Param("id") String id,@Param("ok") long ok);

    /**
     * @Author 高欢
     * @Description  活动展示列表,必须时审核通过的 ok = 1
     * @Date 15:40 2019/4/6
     **/
    List<TbActivity> findTbActivitiesByOk(long ok);

    /**
     * @Author 高欢
     * @Description  找到还未到期的活动
     * @Date 14:10 2019/4/6
     **/
    TbActivity findTbActivityByIdAndActivityExpiredTimeAfter(String id,Date date);

    //筛选通过审核,未过期的活动
    List<TbActivity> findTbActivitiesByOkAndActivityExpiredTimeAfterOrderByCreateTimeDesc(long ok,Date date);

    //同城活动
    List<TbActivity> findTbActivitiesByActivityLocationAndOk(String activityLocation,long ok);

}
